package com.manager.dao;
import com.manager.domain.Teacher;
public class TeacherDao {
//初始化容器 老师数组 存放老师对象
    Teacher[] teachers = new Teacher[30];
    public boolean addTeacher(Teacher tec) {
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher==null){
                teachers[i]=tec;
                return true;
            }
        }
        return false;
    }
    public int isExists(String id) {
        int index = gitIndex(id);
        return index;
    }

    private int gitIndex(String id) {
        for (int i = 0; i < teachers.length; i++) {
            Teacher teacher = teachers[i];
            if (teacher!=null && teacher.getId().equals(id)){
                return i;
            }
        }
        return -1;
    }

    public void delTeacher(String id) {
        int index = gitIndex(id);
        teachers[index] = null;
    }

    public void upDataTeacher(String id,Teacher newTec) {
        int index = gitIndex(id);
        teachers[index] = newTec;
    }

    public Teacher[] findAllTeacher() {
        return teachers;
    }
}
